package com.example.note.database;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

@Dao
public interface ReminderDao {
    
    @Insert
    long insertReminder(ReminderEntity reminder);
    
    @Update
    void updateReminder(ReminderEntity reminder);
    
    @Delete
    void deleteReminder(ReminderEntity reminder);
    
    @Query("SELECT * FROM reminder ORDER BY reminderTime ASC")
    LiveData<List<ReminderEntity>> getAllReminders();
    
    @Query("SELECT * FROM reminder WHERE id = :id")
    LiveData<ReminderEntity> getReminderById(int id);
    
    @Query("SELECT * FROM reminder WHERE isCompleted = 0 ORDER BY reminderTime ASC")
    LiveData<List<ReminderEntity>> getActiveReminders();
    
    @Query("SELECT * FROM reminder WHERE isCompleted = 1 ORDER BY reminderTime DESC")
    LiveData<List<ReminderEntity>> getCompletedReminders();
    
    @Query("SELECT * FROM reminder WHERE reminderTime <= :currentTime AND isCompleted = 0")
    List<ReminderEntity> getDueReminders(long currentTime);
    
    @Query("UPDATE reminder SET isCompleted = 1 WHERE id = :id")
    void markReminderAsCompleted(int id);
    
    @Query("DELETE FROM reminder WHERE id = :id")
    void deleteReminderById(int id);
    
    @Query("SELECT COUNT(*) FROM reminder WHERE isCompleted = 0")
    LiveData<Integer> getActiveReminderCount();
}